package com.lb.shopguide.trace;

import android.content.Context;

import com.blankj.utilcode.util.DeviceUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.lb.baselib.http.ResponseCode;
import com.lb.baselib.http.SimpleLbObserver;
import com.lb.baselib.http.SimpleObserverOnNextListener;
import com.lb.baselib.http.SimpleObserverOtherListener;
import com.lb.baselib.http.bean.BaseResponse;
import com.lb.shopguide.config.AppConfigManager;
import com.lb.shopguide.entity.order.CommitOrderReplyBean;
import com.lb.shopguide.entity.trace.TraceBean;
import com.lb.shopguide.http.method.ApiMethodGuide;
import com.lb.shopguide.ui.fragment.guide.FragmentMain;
import com.lb.shopguide.ui.fragment.guide.order.FragmentCheckout;
import com.lb.shopguide.ui.fragment.guide.pay.FragmentPayResult;
import com.lb.shopguide.util.json.JsonUtil;
import com.qmuiteam.qmui.util.QMUIDeviceHelper;
import com.trello.rxlifecycle2.android.FragmentEvent;

import okhttp3.RequestBody;

public class TraceManager {
    private static TraceManager mTraceManager;
    private TraceManager(Context context) {

    }

    public static TraceManager getTraceManager(Context ctx) {
        if (mTraceManager == null) {
            mTraceManager = new TraceManager(ctx);
        }
        return mTraceManager;
    }

    public  void trackFinishGuide(TraceBean bean){
        trackBean(bean);
    }

    public  void trackUpdateApp(TraceBean bean){
        trackBean(bean);
    }

    public void trackViewGoods(TraceBean bean){//后期可以根据具体业务扩展
        trackBean(bean);
    }

    public void trackShareGoods(TraceBean bean){
        trackBean(bean);
    }

    private  void trackBean(TraceBean bean){
        bean.setDeviceId(DeviceUtils.getAndroidID());
        String json = JsonUtil.getGson().toJson(bean);
        RequestBody body =RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"), json);
        if (body != null) {
            SimpleObserverOnNextListener<BaseResponse> listener = response -> {
                if (response.getReturnCode() == (ResponseCode.RESPONSE_SUCCESS)) {
                }
            };
            SimpleObserverOtherListener errorListener = new SimpleObserverOtherListener() {
                @Override
                public void onSessionOutOfDate() {

                }

                @Override
                public void onError(String error) {

                }
            };
            ApiMethodGuide.collectData(new SimpleLbObserver(listener, errorListener), body);
        }
    }
}
